<%@page import="java.util.Map"%>
<%@page import="entities.MetaSeo"%>
<%@page import="systems.ConfigSystem"%>
<%@page import="entities.SiteConfig"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.User"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.Article"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
SiteConfig siteConfig = ConfigSystem.getConfigs();

TreeMap check = (TreeMap) request.getAttribute("check");
Article article = (Article) request.getAttribute("article");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String success = (String)request.getAttribute("success");
User user = (User) request.getAttribute("user_logged_in");
String url = (String) request.getAttribute("url");
LanguageHelper translate = (LanguageHelper) request.getAttribute("translate");

MetaSeo metaseo = (MetaSeo) request.getAttribute("metaseo");

//Set content for Seo
Map<String, String> replates = new TreeMap<String, String>();
replates.put("__SERVER_NAME__", UrlHelper.getDomainServer(request));
replates.put("__SERVER_URL__", UrlHelper.getServerUrl(request));

String title = StringHelper.replateContent(metaseo.getTitle(), replates);
String description = StringHelper.replateContent(metaseo.getDescription(), replates);
String keywords = StringHelper.replateContent(metaseo.getKeywords(), replates);
String ogurl = StringHelper.replateContent(metaseo.getOgurl(), replates);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/templates/ezsarticle/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=ogurl %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

	<script src="/sources/ckeditor/ckeditor.js"></script>
	
		<div class="row-fluid">
			<div class="span8">
				<div class="block contact">
					<h3 class="title">Submit article</h3>
					<% if (success != null) { %>
					<div class="alert alert-success">
						<button type="button" class="close" data-dismiss="alert">&times;</button>
					  	<%=success %>
					</div>
					<% } %>
					<form method="post" action="">
						<% if (user == null) { %>
						<div class="row-fluid">
							<div class="span6 <%=check.get("name") != null ? "error" : "" %>">
								<label>Author Name (Required)</label>
								<input type="text" class="input-large" tabindex="1" name="name" value="<%=article.getAuthorName() %>">
								<% if (check.get("name") != null ) { %>
			                    <span class="help-inline"><%=check.get("name") %></span>
			                    <% } %>
							</div>
							<div class="span6 <%=check.get("email") != null ? "error" : "" %>">
								<label>Author Email (Required)</label>
								<input type="text" class="input-large" tabindex="2" name="email" value="<%=article.getEmail() %>">
								<% if (check.get("email") != null ) { %>
			                    <span class="help-inline"><%=check.get("name") %></span>
			                    <% } %>
							</div>
						</div>
						<% } %>
						
						<div class="row-fluid">
							<div class="span6 <%=check.get("title") != null ? "error" : "" %>">
								<label>Article Title (Required)</label>
								<input type="text" class="input-large" tabindex="3" name="title" value="<%=article.getTitle() %>" >
								<% if (check.get("title") != null ) { %>
			                    <span class="help-inline"><%=check.get("title") %></span>
			                    <% } %>
							</div>
							<div class="span6 <%=check.get("category") != null ? "error" : "" %>">
								<label>Category (Required)</label>
								<select name="category">
	                            	<% for (Category category : categories) { %>                                
	                                <option value="<%=category.getId()%>" <%=category.getId().equalsIgnoreCase(article.getCategory()) ? "selected=\"selected\"" : "" %>><%=category.getName() %></option>
	                                <% } %>
	                            </select>
	                            <% if (check.get("category") != null ) { %>
			                    <span class="help-inline"><%=check.get("category") %></span>
			                    <% } %>
							</div>
						</div>
						
						<div class="row-fluid">
							<div class="span12 <%=check.get("content") != null ? "error" : "" %>">
								<label>Content (Required)</label>
								<textarea name="content" rows="8" class="input-xxlarge ckeditor"><%=article.getContent() %></textarea>
								<% if (check.get("content") != null ) { %>
			                    <span class="help-inline"><%=check.get("content") %></span>
			                    <% } %>
							</div>
						</div>
						
						<div class="row-fluid">
							<div class="span12 <%=check.get("keywords") != null ? "error" : "" %>">
								<label>Keyword</label>
								<input type="text" class="input-xxlarge" tabindex="1" name="keywords" value="<%=StringHelper.listToString(article.getKeywords(), ", ")%>">
								<% if (check.get("keywords") != null ) { %>
			                    <span class="help-inline"><%=check.get("keywords") %></span>
			                    <% } %>
							</div>
						</div>
						
						<% if (user == null) { %>
						<div class="row-fluid">
							<div class="span12 <%=check.get("website") != null ? "error" : "" %>">
								<label>Author Website</label>
								<input type="text" class="input-xxlarge" tabindex="1" name="website" value="<%=url != null ? url : article.getWebsite()%>">
								<% if (check.get("website") != null ) { %>
			                    <span class="help-inline"><%=check.get("website") %></span>
			                    <% } %>
							</div>
						</div>
						
						<div class="row-fluid">
							<div class="span12 <%=check.get("captcha") != null ? "error" : "" %>">
								<label>Security Code (<a href="/login">login</a> to remove captcha)</label>
								<script>
						        	var RecaptchaOptions = { theme : 'red'};
						  		</script>
								<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
								<% if (check.get("captcha") != null ) { %>
			                    <span class="help-inline"><%=check.get("captcha") %></span>
			                    <% } %>
							</div>
						</div>
						<% } %>
						
						<div id="article-submit">
							<p></p><input type="submit" class="btn btn-success" value="Save" tabindex="5" id="submit" name="submit"><p></p>
						</div>
						
					</form>
				</div>
			</div>
			
			<jsp:include page="/templates/ezsarticle/elements/right.jsp" />
			
		</div>

<jsp:include page="/templates/ezsarticle/layouts/footer.jsp" />